﻿<!DOCTYPE html
  PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
  <meta http-equiv="X-UA-Compatible" content="IE=EDGE;IE=11;IE=8,chrome=1" />
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>工位维护</title>
  <link href="/InSiteWebApplication/Content/Easyui/themes/metro/easyui.css" rel="stylesheet" />
  <link href="/InSiteWebApplication/Content/Easyui/custom-easyui.css" rel="stylesheet" />
  <link href="/InSiteWebApplication/Content/Easyui/themes/icon.css" rel="stylesheet" />
  <link rel="stylesheet" href="/InSiteWebApplication/Content/webuploader/webuploader.css" />
  <style>
    .easyui-linkbutton {
      margin-left: 20px;
    }

    table tr td {
      padding: 0px 5px
    }

    .Btitle {
      background-color: #ddd;
      padding: 10px;
      margin: 5px 10px;
    }

    .webuploader-pick {
      padding: 0px 0px;
      border-radius: 0px
    }
  </style>
</head>

<body>
  <div class="panelSection">
    <div class="easyui-panel " title="查询区域" style="padding:3px;width: 100%"
      data-options="closable:false,collapsible:true,minimizable:false,maximizable:false">
      <form id="searchForm" method="post">
        <table>
          <tr class="divLabel">
            <td>分厂:</td>
            <td>班:</td>
          </tr>
          <tr>
            <td><input id="selFactory" name="Factory" class="easyui-combobox" style="width: 120px; height: 22px"
                data-options='editable:false' /></td>
            <td><input id="selShift" name="shift" class="easyui-combobox" style="width: 120px; height: 22px"
                data-options='editable:false' /></td>
            <td><a href="javascript:void(0)" class="easyui-linkbutton" onclick="page.searchData()">查询</a></td>
            <td><a href="javascript:void(0)" class="easyui-linkbutton" onclick="page.searchReset()">重置</a></td>
          </tr>
        </table>
      </form>
    </div>
  </div>

  <div class="panelSection">
    <div class="easyui-panel " title="查询结果" style="padding:3px;width: 100%"
      data-options="closable:false,collapsible:true,minimizable:false,maximizable:false">
      <table id="WorkStation" style="height:240px;width: 100%" data-options="rownumbers:true"></table>
    </div>
  </div>
  <div class="panelSection">
    <div class="easyui-panel " title="基本信息" style="padding:3px;width: 100%"
      data-options="closable:false,collapsible:true,minimizable:false,maximizable:false">
      <form id="EditorForm" method="post">
        <table>
          <tr class="divLabel">
            <td>分厂:</td>
            <td>班:</td>
            <td>工位名:</td>
            <td>工位额定工时:</td>
            <!--<td>是否瓶颈工位</td>-->
          </tr>
          <tr>
            <td><input id="selFactory1" name="FACTORYID" class="easyui-combobox" style="width: 120px; height: 22px"
                data-options='editable:false' /></td>
            <td><input id="selShift1" name="SHIFTID" class="easyui-combobox" style="width: 120px; height: 22px"
                data-options='editable:false' /></td>
            <td><input id="WorkStationName" name="WORKSTATIONNAME" class="easyui-textbox"
                style="width: 120px; height: 22px" /></td>
            <td><input id="QuotaMins" name="QUOTAMINS" class="easyui-numberbox"
                style="width: 120px; height: 22px" /><input name="WORKSTATIONID" type="hidden" /></td>
            <!-- <td><input id="IsBottLeneck" name="ISBOTTLENECK" class="easyui-combobox" style="width: 120px; height: 22px" data-options='editable:false'/></td>-->
          </tr>
        </table>
      </form>
    </div>
  </div>

  <div class="panelSection">
    <div class="easyui-panel " title="人员信息" style="padding:3px;width: 100%"
      data-options="closable:false,collapsible:true,minimizable:false,maximizable:false">
      <div style="float: left;padding-top: 43px;">
        <table id="tbEmployee" class="easyui-datagrid" style="width: 350px;height: 300px;"
          data-options="rownumbers:true"></table>
      </div>
      <div style="float: left;width:90px;padding-top: 57px;">
        <button class="easyui-linkbutton" onclick="page.removeEmployee()" data-options=""
          style="margin:100px 10px 60px;">移除&gt;&gt;</button>
        <button class="easyui-linkbutton" onclick="page.addEmployee()" data-options="" style="margin:0 10px;">&lt;&lt;
          添加</button>
      </div>
      <div style="float: left;">
        <form id="employeeForm">
          <table>
            <tr class="divLabel">
              <td>姓名：</td>
              <td>员工号：</td>
            </tr>
            <tr>
              <td><input id="Text1" class="easyui-textbox" name="FullName" style="width: 120px; height: 22px" /></td>
              <td><input id="Text2" class="easyui-textbox" name="EmployeeName" style="width: 120px; height: 22px" />
              </td>
              <td><a href="javascript:void(0)" class="easyui-linkbutton" onclick="page.searchEmployee()">搜索</a></td>
            </tr>
          </table>
        </form>
        <table id="ddEmployee" class="easyui-datagrid" style="width: 350px;height: 300px;"
          data-options="rownumbers:true"></table>
      </div>
    </div>
  </div>

  <div class="panelSection">
    <div class="easyui-panel " title="按钮区域" style="padding:3px;width: 100%"
      data-options="closable:false,collapsible:true,minimizable:false,maximizable:false">
      <a href="javascript:void(0)" onclick="page.CreateWorkStationEmployee()" class="easyui-linkbutton"
        data-options="width:120" style="margin: 10px 0 10px 20px;">新建</a>
      <a href="javascript:void(0)" onclick="page.BindWorkStationEmployee()" class="easyui-linkbutton"
        data-options="width:120" style="margin: 10px 0 10px 20px;">保存</a>
      <a href="/InSiteWebApplication/Temp2/导入模板/工位维护导入模板.xlsx" class="easyui-linkbutton">模板下载</a>
      <a href="javascript:void(0);" id="btnWorkStationImport" class="easyui-linkbutton" style="height:auto">工位信息导入</a>
      <span style="color:red;font-weight:bold;margin-left: 10px;">内部系统，禁止处理涉密信息！</span>
      <input id="txtExcelFileId" type="hidden" />
    </div>
  </div>
  <!--信息提示区域-->
  <div id="statusMessage" style="font-size: 14px; height: 40px"></div>
  <div id="ErrorDg" style="display:none">
    <table id="ErrorTable" class="easyui-datagrid" data-options="rownumbers:true"></table>
  </div>
</body>

</html>
<script src="/InSiteWebApplication/Scripts/json2.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Content/Easyui/jquery.min.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Content/Easyui/jquery.easyui.min.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Content/Easyui/easyui-lang-zh_CN.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Scripts/array.pollyfill.js" type="text/javascript"></script>
<script type="text/javascript" src="/InSiteWebApplication/Content/webuploader/webuploader.js"></script>
<script src="/InSiteWebApplication/Scripts/CustomPageJs/CustomCommon.js" type="text/javascript"></script>
<script>
  //创建人：longb
  //日期：2022-08-11
  //描述：工位维护
  var page = {
    rootPath: getRootPath(), //网站根路径
    ajaxUrl: getRootPath() + "/Ashx/ApsHandler/ApsWorkStationHandler.ashx",
    init: function () {
      page.initPageData();
      page.bind();
      page.InitUploader();
    },
    initPageData: function () {
      page.post({ action: "GetFactory" }, true, function (res) {
        //绑定工厂下拉框
        page.bindFactory('selFactory', res.DBDataSet.dtFactory, 'selShift');
        page.bindFactory('selFactory1', res.DBDataSet.dtFactory, 'selShift1');
      });
    },
    bindFactory: function (id, data, shiftid) {
      $("#" + id).combobox({
        valueField: 'FACTORYID',
        textField: 'FACTORYNAME',
        panelHeight: 200,
        data: data, //下拉数据
        onSelect: function (record) {
          if (record.FACTORYID !== "") {
            page.bindShift(record.FACTORYID, shiftid); //加载工区
          }
        }
      });
      $('#IsBottLeneck').combobox({
        valueField: 'id',
        textField: 'text',
        panelHeight: 200,
        data: [{ id: 0, text: '否' }, { id: 1, text: '是' }]
      });
    },
    //绑定班组
    bindShift: function (factoryid, shiftid) {
      page.post({ action: "GetShift", factoryid: factoryid }, false, function (res) {
        if (res.Result) {
          //绑定班组
          $("#" + shiftid).combobox({
            valueField: 'SHIFTID',
            textField: 'SHIFTNAME',
            panelHeight: 200,
            data: res.DBTable, //下拉数据
            onSelect: function (record) {
              if (shiftid == "selShift1") {
                //page.GetTeamEmployees(record.TEAMID);
              }
            }
          });
        }
      });
    },
    //页面事件绑定
    bind: function () {
      $('#WorkStation').datagrid({
        singleSelect: true,
        columns: [[
          { field: 'FACTORYNAME', title: '分厂', width: 150 },
          { field: 'SHIFTNAME', title: '班', width: 120 },
          { field: 'WORKSTATIONNAME', title: '工位名', width: 120 },
          { field: 'QUOTAMINS', title: '工位额定工时', width: 120 },
          //{ field: 'ISBOTTLENECK', title: '是否瓶颈工位', width: 120 },
          { field: 'FULLNAME', title: '创建人', width: 120 },
          { field: 'CREATEDATE', title: '创建时间', width: 150 },
          { field: 'LASTCHANGEDATE', title: '最后修改日期', width: 150 },
          {
            field: 'delete', title: '操作', width: 150, align: 'center', formatter: function (value, row, index) {
              var html = '<a href="javascript:void(0)" class="easyui-linkbutton l-btn" style="width:50px" onclick=page.deleteWorkStation(\'' + row.WORKSTATIONID + '\')>删除</a>';
              return html;
            }
          }
        ]],
        onSelect: function (index, row) {
          //$('#EditorForm').form('load', row);
          //page.GetWorkStationEmployee(row.WORKSTATIONID);
        },
        onClickCell: function (index, field, value) {
          if (field != "delete") {
            var row = $('#WorkStation').datagrid('getRows')[index];
            $('#EditorForm').form('load', row);
            page.GetWorkStationEmployee(row.WORKSTATIONID);
          }
        }
      });

      var columns = [{ field: 'EMPLOYEEID', width: 50, checkbox: true }, { field: 'EMPLOYEENAME', title: '员工号', width: 150 }, { field: 'FULLNAME', title: '姓名', width: 150 }]
      $('#tbEmployee').datagrid({ columns: [columns] });
      $('#ddEmployee').datagrid({ columns: [columns] });
    },
    //查询
    searchData: function () {
      clearMessage();
      page.GetWorkStation();
      page.CreateWorkStationEmployee();
    },
    //查询重置
    searchReset: function () {
      $('#searchForm').form('clear');
      page.bind();
      clearMessage();
    },
    //查询任务单信息
    GetWorkStation: function () {
      var frdata = $('#searchForm').serializeArray();
      var data = {};
      $.each(frdata, function () {
        data[this.name] = this.value
      });
      var param = {
        action: "GetWorkStation",
        data: JSON.stringify([data])
      };
      page.post(param, true, function (res) {
        $('#WorkStation').datagrid('loadData', res.DBTable);
      });
    },
    GetWorkStationEmployee: function (WorkStationID) {
      var param = {
        action: "GetWorkStationEmployee",
        WorkStationID: WorkStationID
      };
      page.post(param, true, function (res) {
        $('#tbEmployee').datagrid('loadData', res.DBTable);
      });
    },
    //保存
    BindWorkStationEmployee: function () {
      var frdata = $('#EditorForm').serializeArray();
      var data = {};
      $.each(frdata, function () {
        data[this.name] = this.value
      });
      if (data.FACTORYID == "") { displayMessage('请选择分厂，再进行保存', false); return; }
      if (data.TEAMID == "") { displayMessage('请选择组，再进行保存', false); return; }
      if (data.WORKSTATIONNAME == "") { displayMessage('请输入工位名，再进行保存', false); return; }
      if (data.QUOTAMINS == "") { displayMessage('请输入工位定额工时，再进行保存', false); return; }
      var rows = $('#tbEmployee').datagrid('getRows');
      var param = {
        action: "SaveWorkStation",
        data: JSON.stringify([data]),
        employees: JSON.stringify(rows)
      };
      page.post(param, true, function (res) {
        if (res.Result) {
          page.GetWorkStation();
        }
        displayMessage(res.Message, res.Result);
      });
    },
    //删除工位
    deleteWorkStation: function (workStationid) {
      page.post({ action: "DeleteWorkStation", workStationid: workStationid }, true, function (res) {
        if (res.Result) {
          page.GetWorkStation();
          page.CreateWorkStationEmployee();
        }
        displayMessage(res.Message, res.Result);
      });
    },
    CreateWorkStationEmployee: function () {
      $('#tbEmployee').datagrid('loadData', []);
      $('#EditorForm').form('clear');
    },
    //查询员工
    searchEmployee: function () {
      var frdata = $('#employeeForm').serializeArray();
      var data = {};
      $.each(frdata, function () {
        data[this.name] = this.value
      });
      var ids = [];
      var rows = $('#tbEmployee').datagrid('getRows');
      $.each(rows, function (index, item) {
        ids.push(item.EMPLOYEEID);
      });
      var param = {
        action: "GetEmployee",
        data: JSON.stringify([data]),
        ids: ids.join(',')
      };
      page.post(param, true, function (res) {
        $('#ddEmployee').datagrid('loadData', res.DBTable);
      });
    },
    //移出
    removeEmployee: function () {
      var rows = $('#tbEmployee').datagrid('getChecked');
      if (rows.length == 0) { displayMessage('请勾选已关联人员信息，再进行移出操作', false); }
      $.each(rows, function (index, item) {
        var index1 = $('#tbEmployee').datagrid('getRowIndex', item);
        if (index1 != -1) {
          $('#tbEmployee').datagrid('deleteRow', index1);
          $('#ddEmployee').datagrid('appendRow', item);
        }
      })
    },
    //移入
    addEmployee: function () {
      var rowss = $('#ddEmployee').datagrid('getChecked');
      if (rowss.length == 0) { displayMessage('请勾选已关联人员信息，再进行移入操作', false); }
      var tbRows = $('#tbEmployee').datagrid('getRows');
      rowss.forEach(function (item) {
        var isExist = tbRows.some(function (i) {
          return i.EMPLOYEEID === item.EMPLOYEEID
        })
        if (!isExist) {
          var index = $('#ddEmployee').datagrid('getRowIndex', item);
          $('#tbEmployee').datagrid('appendRow', item);
          $('#ddEmployee').datagrid('deleteRow', index);
        }
      });
    },
    //导入组件初始化
    InitUploader: function () {
      var uploader = WebUploader.create({
        // swf文件路径
        swf: page.rootPath + "/Content/webuploader/Uploader.swf",
        // 文件接收服务端。
        server: page.ajaxUrl,
        // 内部根据当前运行是创建，可能是input元素，也可能是flash.
        pick: '#btnWorkStationImport',
        // 不压缩image, 默认如果是jpeg，文件上传前会压缩一把再上传！
        resize: false,
        formData: {
          action: "ImportWorkStation",
        },
        accept: {
          title: 'Excel',
          extensions: 'xlsx,xls',
          mimeTypes: 'excel/*'
        },
      });
      // 当有文件被添加进队列的时候，每次只传一个文件
      uploader.on('fileQueued', function (file) {
        if ($('#txtExcelFileId').val() != "") {
          var f = uploader.getFile($('#txtExcelFileId').val()); //找到上一次队列中的文件
          uploader.removeFile(f, true); //删除掉上一次队列中的文件
        }
        $('#txtExcelFileId').val(file.id);
        displayMessage("", true);
        uploader.upload();
        $.messager.progress({ text: '', msg: '处理中...' });
      });
      //上传成功
      uploader.on('uploadSuccess', function (file, response) {
        displayMessage("", true);
        var result = response;
        displayMessage(result.Message, false);
        $.messager.progress('close');
        if (result.ReturnData != null) { if (result.ReturnData.length > 0) { page.loadErrorData(result.ReturnData); } }
        var f = uploader.getFile(file.id); //找到上传的文件
        uploader.removeFile(f, true); //将其从队列中的删掉
        $('#txtExcelFileId').val("");

      });
      //上传失败
      uploader.on('uploadError', function (file) {
        displayMessage("上传失败", false);
        var f = uploader.getFile(file.id); //找到上传的文件
        uploader.removeFile(f, true); //将其从队列中的删掉
        $.messager.progress('close');
        $('#txtExcelFileId').val("");

      });
    },
    loadErrorData: function (data) {
      $('#ErrorDg').dialog({
        title: '导入错误数据',
        top: 50,
        width: '800px',
        height: '400px',
        closed: false,
        cache: false,
        modal: true,
        buttons: [{
          text: '关闭',
          handler: function () { $('#ErrorDg').dialog('close'); }
        }]
      });
      $("#ErrorTable").datagrid({
        data: data,
        columns: [[
          { field: 'workstation', title: '工位', width: '100px' },
          { field: 'Error', title: '出错原因', width: '600px' }
        ]]
      });
    },
    //清除方法，重要！！！
    reset: function (iscondition, isresult) {
      clearMessage();
    },

    //post数据
    post: function (param, async, callback) {
      $.ajax({
        type: "Post",
        url: page.ajaxUrl,
        data: param,
        cashe: false,
        async: async,
        dataType: "json",
        beforeSend: function () {
          $.messager.progress({ text: '', msg: '处理中...' });
        },
        success: function (data) {
          $.messager.progress('close');
          callback(data);
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
          $.messager.progress('close');
          displayMessage(XMLHttpRequest.responseText, false);
        }
      });
    }
  }
  $(function () {
    page.init();
  });



</script>